<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {
	
	
		function index()
	{
		$this->load->helper('form');
		$this->load->helper('url');
		$this->load->library('session');
		$this->load->library('form_validation');
		$this->form_validation->set_rules('email','email','required');
		$this->form_validation->set_rules('pwd','pwd','required');
		if($this->form_validation->run() == false){
			$this->load->view('login_view');
		} else {
			$email  = $this->input->post('email');
			$pwd = $this->input->post('pwd');
			$this->load->model('login_model');
			if($this->login_model->check_user($email,$pwd) != false){
				$this->session->set_userdata('logged_in', true);
				$this->session->set_userdata('user_id', $email); 
				redirect('http://redwolf.cdf.toronto.edu:8830/ci/index.php/main'); 

			} else {
				echo '<script>alert("Wrong email address or wrong passsword");</script>'; 
				$this->load->view('login_view');
			}

		}
	}
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
?>